1 /*
2  * Hunt - a framework for web and console application based on Collie using Dlang development
3  *
4  * Copyright (C) 2015-2017  Shanghai Putao Technology Co., Ltd
5  *
6  * Developer: HuntLabs
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.routing.define;
13 
14 public import kiss.logger;
15 
16 public import hunt.http.request;
17 
18 public import std.exception;
19 
20 // default route group name
21 enum DEFAULT_ROUTE_GROUP = "default";
22 
23 alias HandleFunction = void function(Request);
24 
25 // support methods
26 enum HTTP_METHODS {
27     GET = 1,
28     POST,
29     PUT,
30     DELETE,
31 	HEAD,
32 	OPTIONS,
33 	PATCH,
34 	ALL
35 }
36 
37 HTTP_METHODS getMethod(string method)
38 {
39 	with(HTTP_METHODS){
40     if(method == "POST")
41         return POST;
42     else if (method == "GET")
43         return GET;
44     else if (method == "PUT")
45         return PUT;
46     else if (method == "DELETE")
47         return DELETE;
48     else if (method == "HEAD")
49         return HEAD;
50     else if (method == "OPTIONS")
51         return OPTIONS;
52     else if (method == "PATCH")
53         return PATCH;
54     else if (method == "*")
55         return ALL;
56     else 
57         throw new Exception("unkonw method");
58 	}
59 }
60 HTTP_METHODS[] stringToHTTPMethods(string method)
61 {
62 	with(HTTP_METHODS){
63     if(method == "POST")
64         return [POST];
65     else if (method == "GET")
66         return [GET];
67     else if (method == "PUT")
68         return [PUT];
69     else if (method == "DELETE")
70         return [DELETE];
71     else if (method == "HEAD")
72         return [HEAD];
73     else if (method == "OPTIONS")
74         return [OPTIONS];
75     else if (method == "PATCH")
76         return [PATCH];
77     else if (method == "*")
78         return [GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH];
79     else 
80         throw new Exception("unkonw method");
81 	}
82 }